package com.ad2campaign.engine.core.bootstrap;

import java.io.IOException;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.ad2campaign.engine.utils.DatasourceUtil;

public class SetupDatabases {

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		if (!DatasourceUtil.checkDatasource()) {
			System.out
					.println("You must have forgotten to provide mysql database connection setting at conf/settings.conf");
			System.out
					.println("Must set key [batch.jdbc.driver]   value [driver class of mysql]");
			System.out
					.println("Must set key [batch.jdbc.url]      value [jdbc connecion URL]");
			System.out
					.println("Must set key [batch.jdbc.user]     value [mysql user name]");
			System.out
					.println("Must set key [batch.jdbc.password] value [mysql password]");
			System.exit(-1);
		}
		System.out.println("Setting up spring batch database");
		try {
			new ClassPathXmlApplicationContext("setup-beans/setup-batch-database.xml");
		} catch (Exception e) {
			System.out
					.println("Either parially of fully, but batch schema  is already there !");
			System.out.println("Details error message :[" + e.getMessage()
					+ "]");
		}

		System.out.println("Setting up spring nodes database");
		try {
			new ClassPathXmlApplicationContext("setup-beans/setup-nodes-database.xml");
		} catch (Exception e) {
			System.out
					.println("Either parially of fully, but nodes schema  is already there !");
			System.out.println("Details error message :[" + e.getMessage()
					+ "]");
		}
	}

}
